home *** CD-ROM | disk | FTP | other *** search
/ Network CD 2 / Network CD - Volume 2.iso / programs / internet / tcp / clients / atcp_ttcp10.lha / amiga / autotimer.c next >
Encoding:
C/C++ Source or Header  |  1993-10-02  |  3.6 KB  |  158 lines

  1. #ifndef NOIDENT
  2. const static char RCSid[] = "$Header: qc:c-src/common/misclib/RCS/autotimer.c,v 1.1 1993/10/02 10:57:47 alph Exp $";
  3. #endif
  4.  
  5. /*
  6.  *----------------------------------------------------------------------
  7.  *
  8.  * $Source: qc:c-src/common/misclib/RCS/autotimer.c,v $
  9.  * $Revision: 1.1 $
  10.  * $Date: 1993/10/02 10:57:47 $
  11.  * $State: Exp $
  12.  * $Author: alph $
  13.  * $Locker:  $
  14.  *
  15.  *----------------------------------------------------------------------
  16.  *
  17.  * alph --- SAS C auto initialization functions
  18.  * 
  19.  * This code is (C) Copyright 1993 by Carsten Heyl. All rights reserved.
  20.  * This code is NOT in the Public Domain.
  21.  * It may not be copied or distributed without a license.
  22.  *
  23.  *----------------------------------------------------------------------
  24.  * $Log: autotimer.c,v $
  25.  * Revision 1.1  1993/10/02  10:57:47  alph
  26.  * Initial revision
  27.  *
  28.  *----------------------------------------------------------------------
  29.  */
  30.  
  31. #include <exec/types.h>
  32. #include <exec/memory.h>
  33. #include <exec/libraries.h>
  34. #include <devices/timer.h>
  35.  
  36. #include <intuition/intuition.h>
  37.  
  38. #include <proto/exec.h>
  39. #include <proto/intuition.h>
  40.  
  41. #include <stdlib.h>
  42.  
  43. extern STRPTR _ProgramName;    /* SAS startup module defines this :-) */
  44.  
  45. struct Library *TimerBase = NULL;
  46. struct timerequest *_STtr = NULL;
  47.  
  48. static void DoReq(UBYTE *errorStr)
  49. {
  50.     struct Library *IntuitionBase;
  51.  
  52.     IntuitionBase = OpenLibrary("intuition.library", 36);
  53.   
  54.     if (IntuitionBase != NULL) 
  55.     {
  56.     struct EasyStruct libraryES;
  57.     
  58.     libraryES.es_StructSize = sizeof(libraryES);
  59.     libraryES.es_Flags = 0;
  60.     libraryES.es_Title = _ProgramName;
  61.     libraryES.es_TextFormat = errorStr;
  62.     libraryES.es_GadgetFormat = "Exit %s";
  63.     
  64.     EasyRequestArgs(NULL, &libraryES, NULL, (APTR)&_ProgramName);
  65.  
  66.     CloseLibrary(IntuitionBase);
  67.     }
  68. }
  69.  
  70. /****** amiga.lib/autoinit *********************************************
  71. *
  72. *   NAME   
  73. *       autoinit - SAS C Autoinitialization Functions 
  74. *
  75. *   SYNOPSIS
  76. *       _STIopenTimerDev()
  77. *
  78. *       void _STIopenTimerDev(void)
  79. *
  80. *       _STDcloseTimerDev()
  81. *
  82. *       void _STDcloseTimerDev(void)
  83. *
  84. *   FUNCTION
  85. *       These functions open and close the timer.device at the
  86. *       startup and exit of the program, respectively. For a
  87. *       program to use these functions, it must be linked with
  88. *       autotimer.o.
  89. *
  90. *   NOTES
  91. *
  92. *       The autoinitialization and autotermination functions are
  93. *       features specific to the SAS C6. However, these functions
  94. *       can be used with other (ANSI) C compilers, too. Example
  95. *       follows: 
  96. *
  97. *       \* at start of main() *\
  98. *
  99. *       atexit(_STDcloseTimerDev);
  100. *       _STDopenTimerDev();
  101. *
  102. *   BUGS
  103. *
  104. *   SEE ALSO
  105. *       bsdsocket.library/SetErrnoPtr(),
  106. *       SAS/C 6 User's Guide p. 145 for details of
  107. *       autoinitialization and autotermination functions.  
  108. *****************************************************************************
  109. *
  110. */
  111.  
  112. void
  113. _STIopenTimerDev(void)
  114. {
  115.     static short done = 0;
  116.  
  117.     if (done++)        /* try only once (SAS/C 6.2 liked to call this twice) */
  118.     return;
  119.  
  120.     /*
  121.      * Check OS version
  122.      */
  123.     if ((*(struct Library **)4)->lib_Version < 37)
  124.     exit(20);
  125.  
  126.     _STtr = (struct timerequest *) AllocMem(sizeof(struct timerequest),
  127.                         MEMF_PUBLIC | MEMF_CLEAR);
  128.     if(!_STtr)
  129.     exit(20);
  130.  
  131.     if(!OpenDevice(TIMERNAME, UNIT_MICROHZ, 
  132.           (struct IORequest *) _STtr, 0L))
  133.     {
  134.     TimerBase = (struct Library *) _STtr->tr_node.io_Device;
  135. #if 0
  136.     DoReq("Open timer ok.");
  137. #endif
  138.     return;
  139.     }
  140.     else
  141.     DoReq("Could not open "TIMERNAME".");
  142.     exit(20);
  143. }
  144.  
  145. void
  146. _STDcloseTimerDev(void)
  147. {
  148.     if (TimerBase) {
  149.     CloseDevice((struct IORequest *) _STtr);
  150.     TimerBase = NULL;
  151.     }
  152.     if(_STtr)
  153.     {
  154.     FreeMem(_STtr, sizeof(struct timerequest));
  155.     _STtr = NULL;
  156.     }
  157. }
  158.